package com.fzhucc.modules.lesson.repository;

import com.fzhucc.modules.lesson.domain.LessonRecord;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
* @website https://eladmin.vip
* @author yyg
* @date 2022-12-07
**/
public interface LessonRecordRepository extends JpaRepository<LessonRecord, Integer>, JpaSpecificationExecutor<LessonRecord> {

    @Query("SELECT a from LessonRecord as a where a.userId=:userId")
    List<LessonRecord> findByUserId(Long userId);

    @Query("SELECT a from LessonRecord as a where a.userId=:userId and a.lessonId=:lesson_id")
    List<LessonRecord> findByUserIdAndLessonId(Long userId, int lesson_id);

    @Query("SELECT a from LessonRecord as a where a.lessonId=:lesson_id")
    List<LessonRecord> findByLessonId(int lesson_id);

    @Query("SELECT a from LessonRecord as a where a.userId=:userId")
    Page<LessonRecord> findByUserIdWithPage(Long userId, Pageable pageable);
}